<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class CheckInfo extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
//            'username' => 'required|regex:/^\w{3,10}$/|unique:user_info,name',
            'username' => 'required|regex:/^\w{3,10}$/',
            'password' => 'required|regex:/^\S{6,20}$/|same:repassword',
            'email' => 'required|email',
            'phone' => 'required|regex:/^1\d{10}$/',
            'checkcode' => 'required'
        ];
    }

    /**
     * 返回错误信息
     *
     * @return array
     * @author jiaxiaofei
     */
    public function messages()
    {
        return [
            'username.required' => '用户名不能为空',
            'username.regex' => '用户名格式错误',
//            'username.unique' => '用户名已经存在',
            'password.required' => '密码不能为空',
            'password.regex' => '密码格式不正确',
            'password.same' => '两次密码不一致',
            'email.required' => '邮箱不能为空',
            'email.email' => '邮箱格式不正确',
            'phone.required' => '手机号格式不能为空',
            'phone.regex' => '手机号格式不正确',
            'checkcode.required' => '验证码不能为空'
        ];
    }
}